<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\GoodsExtraSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '优惠管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="col-xs-12">
    <div class="box">
        <div class="box-header">
            <p>
                <?= Html::a('新增优惠条件', ['create'], ['class' => 'btn btn-success']) ?>
            </p>
            <!-- Check all button -->
            <!-- /.btn-group -->
            <a type="button" class="btn btn-default btn-sm" href="javascript:window.location.reload()"><i class="fa fa-refresh"></i></a>
            <div class="visible-lg-block pull-right">
                <?php echo $this->render('_search', [
                    'model' => $searchModel,
                ]); ?>
                <!-- /.btn-group -->
            </div>
            <!-- /.pull-right -->
        </div>

        <!-- /.box-header -->
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'layout' => "<div class=\"box-body table-responsive\">{items}</div>\n<div class=\"box-footer clearfix\"><div class=\"row\"><div class=\"col-xs-12 col-sm-7\">{pager}</div><div class=\"col-xs-12 col-sm-5 text-right\">{summary}</div></div></div>",
            'tableOptions'=>['class'=>'table table-bordered table-hover'],
            'summary'=>'第{page}页，共{pageCount}页，当前第{begin}-{end}项，共{totalCount}项',
            'filterModel'=>null,
            'pager'=>[
                'class'=>'yii\widgets\LinkPager',
                'options' => [
                    'class' => 'pagination pagination-sm no-margin',
                ],
            ],
            'columns' => [
                'id',
                [
                    'attribute' => 'goods_id',
                    'value' => function($model){
                        /** @var \common\models\GoodsExtra $model */
                        return $model->good->goods_name;
                    }
                ],
                [
                    'attribute' => 'group_id',
                    'value' => function($model){
                        /** @var \common\models\GoodsExtra $model */
                        return $model->group->group_name;
                    }
                ],
                [
                    'attribute' => 'package_id',
                    'value' => function($model){
                        /** @var \common\models\GoodsExtra $model */
                        return $model->package->package_name;
                    }
                ],
                [
                    'attribute' => 'sale',
                    'value' => function($model){
                        return $model->sale.'%';
                    }
                ],
                [
                    'attribute' => 'created_at',
                    'format' => ['date', 'php:Y-m-d H:i:s'],
                    
                ],
                
                [
                    'class' => 'yii\grid\ActionColumn',
                    'header'=>'操作',
                    'headerOptions'=>['style'=>'width:150px'],
                    'buttonOptions'=>['class'=>'btn btn-default btn-sm'],
                ],
            ],
        ]); ?>
        <!-- /.box-body -->
    </div>
    <!-- /.box -->
</div>
